(function ($app) {
    $app.module('gtPartyApp').controller('summaryCtrl', function ($scope, $http, $modal, $ocLazyLoad, $alert, $loading, $state, $stateParams, AuthUser, $bsRouterState) {

        //定义数据集合
        $scope.loginUserId = AuthUser.getUser().Id;
        $scope.partyList = []; //列表数据
        $scope.meetingStatisticsList = [];
        $scope.yearList = [];
        $scope.quarterList = [];
        $scope.selectparams = {
            selectdzzdm: '',
            selectdzzmc: '',
            defaultselected: '',
            pageindex: 1,
            pagesize: 1000,
            dzzdm: '',//党组织代码
            isunfold: false,
            beginTime: null,
            endTime: null
        };
        $scope.pageInfo = {ptotal: 0, mergetotal: 0};
        $scope.resetparams = angular.copy($scope.selectparams);
        $scope.shyklxList = [];

        //监视页数变化
        $scope.$watch("selectparams.pageindex", function (newVal, oldVal) {
            if ($scope.pageInfo.ptotal > 0) {
                $scope.getPartyList();
            }
        });

        $scope.$watch("selectparams.selectdzzdm", function (newVal, oldVal) {
            if (newVal != "") {
                $scope.selectparams.dzzdm = $scope.selectparams.selectdzzdm;
                $scope.getPartyList();
            }
        });

        //查询
        $scope.search = function () {
            $scope.getPartyList();
        };

        $scope.getPartyList = function () {
            $http
            ({
                method: 'get', url: '../../api/party/getPartyList', params: $scope.selectparams
            }).then(function (result) {
                $scope.partyList = result.data.item.list;
                $scope.getTargetList();
            });
        };

        //加载列表数据
        $scope.getTargetList = function () {
            $http
            ({
                method: 'get', url: '../../api/shyk/getMeetingStatisticsList', params: $scope.selectparams
            }).then(function (result) {
                console.log(result.data.item)
                $scope.meetingStatisticsList = result.data.item;
            }, function (resp) {
                $scope.showMsg('错误', '服务器错误');
            });
        };

        $scope.getSettingTitle = function (partyCode, type) {
            const settingVo = $scope.meetingStatisticsList.filter(e => e.shykType === type && e.partyCode === partyCode);
            return settingVo.length > 0 ? settingVo[0].count : '0';
        };

        $scope.isSetting = function (partyCode) {
            return $scope.meetingStatisticsList.filter(e => e.partyCode === partyCode).length > 0;
        };

        $scope.exportData = function () {
            var params = "?1=1";
            for (var p in $scope.selectparams) {
                if ($scope.selectparams[p] !== '' && $scope.selectparams[p] !== null)
                    params += ("&" + p + "=" + encodeURI($scope.selectparams[p]));
            }
            window.open('../../api/shyk/exportMeetingStatistics' + params);
        };
        $scope.setisunfold = function () {
            $scope.selectparams.isunfold = !$scope.selectparams.isunfold;
            $scope.$emit('menudatas.toggle', !$scope.selectparams.isunfold);
        };

        $scope.getShyklxList = function () {
            $http({
                method: 'get',
                url: '../../api/dictionary/getDictionaryListByDicTypeKey',
                params: {
                    dicTypeKey: 'shykType'
                }
            }).then(function (result) {
                $scope.shyklxList = result.data;
            }, function (resp) {

            });
        };

        $scope.getShyklxList();

        $scope.reset = function () {
            $scope.selectparams = angular.copy($scope.resetparams);
            $scope.selectparams.dzzdm = AuthUser.getUser().dwId;//党组织代码
            $scope.getPartyList();
        };
    });
})(angular);